let app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        page:1,
        currentTab:0,
        dotation:false,
        status_index:0,
        navData:[{status:1,text:'意向用户'},{status:2,text:'战败客户'},{status:3,text:'订单客户'},{status:4,text:'保有客户'},]
    
      
    },  

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that = this;
        var status = options.status;
        if(status == undefined){

        }else{
            this.setData({
                status:status
            })
        }
        console.log(status);
        let d = app.globalData;
        this.setData({
            platform:d.platform,    
            //open:open,
            width:d.windowWidth,
            height:d.windowHeight,
            statusBarHeight:d.statusBarHeight,
            navHeight:d.navHeight,
            navWidth:d.navWidth,
            navRight:d.navRight,
            marginTop:d.navTitleTop,
            domain:d.domain,
            uploadUrl:d.uploadUrl,
          })
    },
    goBack(){
        wx.navigateBack();
    },
    goIndex(){
        var  url ='/pages/customer/index';
        console.log(url);
        wx.reLaunch({
          url:url
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    switchNav(event){
        var cur = event.currentTarget.dataset.current;
        var status = event.currentTarget.dataset.status;
        console.log(cur);  
        //每个tab选项宽度占1/5
        var singleNavWidth = this.data.width / 5;
        //tab选项居中                            
        this.setData({
            navScrollLeft: (cur - 2) * singleNavWidth
        })      
        if (this.data.currentTab == cur) {
            return false;
        } else {
            //var status = 
            this.setData({
                currentTab: cur,
                status:status
            })
            
            this.getList(status);
          
        }
    },
    switchTab(event){
        var cur = event.detail.current;
        var singleNavWidth = this.data.width / 5;
        var left = (cur - 2) * singleNavWidth;
        this.setData({
            currentTab: cur,
            navScrollLeft: left
        });
    },
    goBack(){
        console.log('go back')
        wx.navigateBack(-1)
      },
    onShow() {

        this.getIndex()
    },
    getIndex(){
       let that = this;
       var open=wx.getStorageSync('open');
       let status = this.data.status;
       console.log(status)
       if(status == undefined){
        status = 1;
       }
       
      wx.request({
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        data: {
          user_id:open.user_id,
          mobile:open.phone,
          page:1,
          status:status
          //phone:open.phone
        
            
        },
        //method: 'POST',
        dataType: 'json',
        timeout: 30000,
        url: app.globalData.platUrl + 'customer/getList',
        success: (res) => {
    
        let data = res.data;
        let navData = that.data.navData;
        navData.forEach(function(ele,index){
            if(ele.status == status){
                that.setData({
                    currentTab:index
                })
            }
        })
        
        console.log(data);
          that.setData({
            list:data.list,
           // navData:data.navData,
        
          })
        }
      
       })
    },
    call(e){
        console.log(e)
        var phone =e.currentTarget.dataset.phone;
        wx.makePhoneCall({
          phoneNumber: phone,
        })
    },
    getList(status){
        let that = this;
        var open=wx.getStorageSync('open');
        
       wx.request({
         headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
         data: {
           user_id:open.user_id,
           mobile:open.phone,
           page:1,
           status:status
           //phone:open.phone
         
             
         },
         //method: 'POST',
         dataType: 'json',
         timeout: 30000,
         url: app.globalData.platUrl + 'customer/getList',
         success: (res) => {
     
         let data = res.data;
         
         console.log(data);
           that.setData({
             list:data.list,
             //navData:data.navData,
         
           })
         }
       
        })
    },
    goto:function(e){
        console.log(e);
        var url = e.currentTarget.dataset.url;
        var index = e.currentTarget.dataset.index;
        var parent_id=wx.getStorageSync('parent_id');
        if(url=="#"){
    
        }else{
            if(url=='index'){
                wx.reLaunch({
                  url: url,
                })
            }else{
                wx.navigateTo({
                    url: url,
                  })
            }
        
        }
        console.log(url);
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})